<include file="Public:header"/>	
<div id="content">
	<div id="content-header">
		<empty name="info['u_id']">
			<h1>添加</h1>
		<else />
			<h1>修改</h1>
		</empty>
		<div class="btn-group">
			<a href="{:U('Admin/Down/index')}" class="btn btn-large" title="下载列表"><i class="fa fa-tasks"></i></a>
		</div>
	</div>
	<div id="breadcrumb">
		<a href="index.html" title="回到首页" class="tip-bottom"><i class="fa fa-home"></i> 首页</a>
		<a href="#">下载</a>
		<empty name="info['d_id']">
		<a href="#" class="current">添加</a>
		<else />
			<a href="#" class="current">修改</a>
		</empty>
	</div>
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon">
							<i class="fa fa-user"></i>									
						</span>
						<empty name="info['d_id']">
						<h5>添加</h5>
						<else />
						<h5>修改</h5>
						<input id="did" value="{$info.d_id}" type="hidden" />
						</empty>
					</div>
					<div class="widget-content nopadding">
						<form action="#" method="post" class="form-horizontal">
							
							<div class="form-group">
                                <label class="col-sm-3 col-md-3 col-lg-1 control-label">程序名</label>
                                <div class=" col-sm-9 col-md-9 col-lg-10">
                                	<div class="input-group input-group-sm">
										<span class="input-group-addon"><i class="fa fa-user"></i></span>
                                    	<input type="text" value="{$info.d_name}" class="form-control input-sm" placeholder="程序名" name="dname" id="dname" />
                                    </div>
                                </div>
                            </div>
							
							<div class="form-group">
                                <label class="col-sm-3 col-md-3 col-lg-1 control-label">下载地址</label>
                                <div class=" col-sm-9 col-md-9 col-lg-10">
                                	<div class="input-group input-group-sm">
										<span class="input-group-addon"><i class="fa fa-laptop"></i></span>
                                    	<input type="text" value="{$info.d_url}" class="form-control input-sm" id="durl" name="durl"/>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
								<label class="col-sm-3 col-md-3 col-lg-1 control-label">是否显示</label>
								<div class="col-sm-9 col-md-9 col-lg-10">
									<select id="dstatic">
										<option value="1" <eq name="info['d_static']" value="1">selected</eq> >显示</option>
										<option value="0" <eq name="info['d_static']" value="0">selected</eq> >隐藏</option>
									</select>
								</div>
							</div>
                           
							<div class="form-actions">
								<empty name="info['d_id']">
								<button type="button" class="btn btn-success btn-sm" id="addfile">存入数据库</button>  
								<else />
								<button type="button" class="btn btn-success btn-sm" id="editfile">存入数据库</button>  
								</empty>
								<button type="button" class="btn btn-danger btn-sm">取消</button>
							</div>
						</form>
					</div>
				</div>						
			</div>
		</div>
	</div>
</div>
<include file="Public:footer"/> 
    <script>
    	$(document).ready(function(){
		$('input[type=checkbox],input[type=radio]').iCheck({
	    	checkboxClass: 'icheckbox_flat-blue',
	    	radioClass: 'iradio_flat-blue'
		});
		$('select').select2();
	    $('.spinner').spinner();
	    $("#addfile").click(function(){
	    	var dname = $("#dname").val();
	    	var durl = $("#durl").val();
	    	var dstatic = $("#dstatic").val();
	    	if(!dname){
	    		err("程序名不能为空!");
	    		return false;
	    	}else if(!durl){
	    		err("下载地址不能为空!");
	    		return false;
	    	}else if(!dstatic){
	    		err("状态不能为空");
	    		return false;
	    	}else{
	    		$("#addfile").attr("disabled",true);
	    		$.ajax({
	    			type:"post",
	    			url:"{:U('/Admin/Down/addH')}",
	    			async:true,
	    			data:{"dname":dname,"durl":durl,"dstatic":dstatic},
					success:function(data){
						if(data.error==0){
							succ("添加成功!",data.msg,"/Admin/Down/index");
						}else if(data.error==1){
							err(data.msg);
							$("#addfile").removeAttr('disabled');
						}
					},
					error:function(data){
						err("网路错误!");
						$("#addfile").removeAttr('disabled');
					}
	    		});
	    	}
	    	
	    });
	    $("#editfile").click(function(){
	    	var did = $("#did").val();
	    	var dname = $("#dname").val();
	    	var durl = $("#durl").val();
	    	var dstatic = $("#dstatic").val();
	    	if(!dname){
	    		err("程序名不能为空!");
	    		return false;
	    	}else if(!durl){
	    		err("下载地址不能为空!");
	    		return false;
	    	}else if(!dstatic){
	    		err("状态不能为空");
	    		return false;
	    	}else{
	    		$("#editfile").attr("disabled",true);
	    		$.ajax({
	    			type:"post",
	    			url:"{:U('/Admin/Down/editH')}",
	    			async:true,
	    			data:{"did":did,"dname":dname,"durl":durl,"dstatic":dstatic},
					success:function(data){
						if(data.error==0){
							succ("修改成功!",data.msg,"/Admin/Down/index");
						}else if(data.error==1){
							err(data.msg);
							$("#editfile").removeAttr('disabled');
						}
					},
					error:function(data){
						err("网路错误!");
						$("#editfile").removeAttr('disabled');
					}
	    		});			    		
	    	}
	    	
	    });
	});
    </script>
</body>
</html>
